package com.anytron.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import com.anytron.config.timer.AppTimerInit;

@Configuration
public class QuartzConfiguration {

	// Quartz配置文件路径
	private static final String QUARTZ_CONFIG = "config/quartz.properties";

	@Bean
	public SchedulerFactoryBean schedulerFactoryBean() {
		SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
		// 设置加载的配置文件
		schedulerFactoryBean.setConfigLocation(new ClassPathResource(QUARTZ_CONFIG));
		// 用于quartz集群,QuartzScheduler 启动时更新己存在的Job
		schedulerFactoryBean.setOverwriteExistingJobs(true);
		schedulerFactoryBean.setStartupDelay(5);// 系统启动后，延迟5s后启动定时任务，默认为0
		// 启动时更新己存在的Job，这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
		schedulerFactoryBean.setOverwriteExistingJobs(true);
		return schedulerFactoryBean;
	}
	
	@Bean(initMethod = "init")
	public AppTimerInit appTimerInit() {
		return new AppTimerInit();
	}
	
}
